package com.hyg.common.view.dialog;

import android.content.Context;

import com.hyg.common.R;


/**
 * Author: zhpan
 * Date: 2022/5/5
 */

public class DialogUtils {
    //  加载进度的dialog
    private CustomProgressDialog mProgressDialog;

    /**
     * 显示ProgressDialog
     */
    public void showProgress(Context context, String msg, boolean cancelTouchOutside) {
       /* if (context == null || context.isFinishing()) {
            return;
        }*/
        if(mProgressDialog==null || !mProgressDialog.isBelongContext(context)){
            mProgressDialog= new CustomProgressDialog.Builder(context)
                    .setTheme(R.style.ProgressDialogStyle)
                    .setMessage(msg)
                    .build();
        }
        mProgressDialog.setCanceledOnTouchOutside(cancelTouchOutside);
        mProgressDialog.setMessage(msg);
        if(mProgressDialog!=null&&!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }
    }

    public void showProgress(Context context, String msg) {
        showProgress(context,msg,true);
    }

    public void showProgress(Context context) {
        showProgress(context,"",true);
    }

    /**
     * 取消ProgressDialog
     */
    public void dismissProgress() {
        if (mProgressDialog != null&&mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }
}
